<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>异步请求</title>
    <script src="js/jquery-1.4.4.min.js"></script>
</head>
<body>
    <input type="button" value="post请求" onclick="clickPost()">
    <input type="button" value="put请求" onclick="clickPut()">
    <input type="button" value="delete请求" onclick="clickDelete()">


</body>
<script type="text/javascript">

    function clickGet(){

        //发起异步请求
        $.ajax({
            type: "get",
            url: "/json/testGet",
            contentType: "application/json",
            success:function(data) {
                console.log(data);
            },
            error:function(data){
                console.log("失败了");
            }
        });
    }
    function clickPost(){
        var param = {"id": 1, "username": '张三', "sex": "男"};

        //发起异步请求
        $.ajax({
            type: "POST",
            data: JSON.stringify(param),
            url: "/user",
            contentType: "application/json",
            success:function(data) {
                alert(data);
            },
            error:function(data){
                console.log("失败了");
            }
        });
    }

    function clickPut(){
        var param = {"id": 1, "username": '张三', "sex": "男"};

        //发起异步请求
        $.ajax({
            type: "PUT",
            data: JSON.stringify(param),
            url: "/user",
            contentType: "application/json",
            success:function(data) {
                alert(data);
            },
            error:function(data){
                console.log("失败了");
            }
        });
    }

    function clickDelete(){

        //发起异步请求
        $.ajax({
            type: "delete",
            url: "/user/1",
            contentType: "application/json",
            success:function(data) {
                alert(data);
            },
            error:function(data){
                console.log("失败了");
            }
        });
    }
</script>
</html>